<template>
<!--  <router-view v-slot="{Component}">
    <transition>
      <keep-alive>
        <component :is="Component"/>
      </keep-alive>
    </transition>
  </router-view>-->
  <div id="nav">
    <router-link class="tab-bar-item" to="/">
      <div class="iconfont icon">&#xe622;</div>
      <div class="text">首页</div>
    </router-link>
    <router-link class="tab-bar-item" to="/category">
      <div class="iconfont icon">&#xe60d;</div>
      <div class="text">分类</div>
    </router-link>
    <router-link to="/shopcart" class="tab-bar-item">
      <div class="iconfont icon">
        <van-badge :content="$store.state.cartCount" max="9">
          &#xe674;
        </van-badge>
      </div>
      <div class="text">购物车</div>
    </router-link>
    <router-link to="/profile" class="tab-bar-item">
      <div class="iconfont icon">&#xe607;</div>
      <div class="text">我的</div>
    </router-link>
  </div>
  <router-view/>
</template>

<script>

import {onMounted} from "vue";
import {useStore} from "vuex";

export default {

  setup(){
    const store=useStore();
    onMounted(()=>{
      store.dispatch(('updateCart'))
    })
  }
}
</script>
<style lang="scss">
@import "./assets/css/iconfont.css";

#nav {
  width: 100%;
  display: flex;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: #f6f6f6;
  height: 50px;
  align-items: center;
  box-shadow: 0 -3px 1px rgba(100, 100, 100, 0.1);
  z-index: 9;

  .tab-bar-item {
    flex: 1;
    text-align: center;
    font-size: 15px;

    &.router-link-exact-active {
      color: var(--color-high-text);
    }

    .icon {
      font-size: 17px;
      margin-bottom: 4px;
    }

  }
}

</style>
